package com.xiaomaoaixue.wecom.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.google.common.collect.Lists;
import com.xiaomaoaixue.common.core.exception.CustomException;
import com.xiaomaoaixue.common.core.utils.SpringUtils;
import com.xiaomaoaixue.constant.WeConstans;
import com.xiaomaoaixue.system.api.RemoteDeptService;
import com.xiaomaoaixue.system.api.domain.SysDept;
import com.xiaomaoaixue.wecom.client.WeDepartMentClient;
import com.xiaomaoaixue.wecom.domain.dto.WeResultDto;
import com.xiaomaoaixue.wecom.exception.wecom.WeComException;
import com.xiaomaoaixue.wecom.service.IWeDepartmentService;
import com.xiaomaoaixue.wecom.service.IWeUserService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 企业微信组织架构相关Service业务层处理
 *
 * @author ruoyi
 * @date 2020-09-01
 */
@Service
public class WeDepartmentServiceImpl   implements IWeDepartmentService {


    @Autowired
    private WeDepartMentClient weDepartMentClient;


    @Autowired
    private RemoteDeptService  remoteDeptService;
    /**
     * 同步部门
     */
    @Override
    public List<SysDept> synchWeDepartment() {
        List<SysDept> weDepartments = weDepartMentClient.weAllDepartMents().findWeDepartments();
        if (CollectionUtil.isNotEmpty(weDepartments)) {
            List<List<SysDept>> lists = Lists.partition(weDepartments, 500);
            for(List<SysDept> list : lists){
                remoteDeptService.syncSysDept(list);
            }
        }
        return weDepartments;
    }




}
